package com.studentmanagement.model;

import java.util.List;

public class PageBean<T> {
    private int pageNum;        // 当前页码
    private int pageSize;       // 每页显示的记录数
    private int totalRecord;    // 总记录数
    private int totalPage;      // 总页数
    private List<T> list;       // 当前页的数据
    private String sortField;   // 排序字段
    private String sortOrder;   // 排序方式（升序/降序）

    public PageBean() {
    }

    public PageBean(int pageNum, int pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.sortOrder = "ASC";
    }

    // Getters and Setters
    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
        // 计算总页数
        this.totalPage = (totalRecord % pageSize == 0) ?
                (totalRecord / pageSize) :
                (totalRecord / pageSize + 1);
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public String getSortField() {
        return sortField;
    }

    public void setSortField(String sortField) {
        this.sortField = sortField;
    }

    public String getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(String sortOrder) {
        this.sortOrder = sortOrder;
    }

    // 判断是否有上一页
    public boolean isHasPreviousPage() {
        return pageNum > 1;
    }

    // 判断是否有下一页
    public boolean isHasNextPage() {
        return pageNum < totalPage;
    }
}